//
//  XSComposeButton.swift
//  WeiDo
//
//  Created by XISHAN on 16/3/11.
//  Copyright © 2016年 XISHAN. All rights reserved.
//

import UIKit

class XSComposeButton: UIButton {

    //按钮显示的数据
    var menuInfo:XSComposeMenuInfo?{
        didSet{
            
            setImage(UIImage(named: menuInfo!.icon!), forState: UIControlState.Normal)
            setTitle(menuInfo!.title!, forState: UIControlState.Normal)
        }
    }
    
    //去掉按钮的高亮效果
    override var highlighted:Bool{
        get{
            return false
        }
        set{
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


    private func setupUI(){
        //文字居中
        titleLabel?.textAlignment = NSTextAlignment.Center
        //文字颜色
        setTitleColor(UIColor.blueColor(), forState: .Normal)
        //文字大小
        titleLabel?.font = UIFont.systemFontOfSize(16)
        //图片原样显示
        imageView?.contentMode = .Center
        
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        
        let width = self.frame.width
        let height = self.frame.height
        //1.调整图片的大小和位置
        imageView?.frame.size = CGSizeMake(width, width)
        imageView?.frame.origin = CGPointZero
        //2.调整label的大小和位置
        titleLabel?.frame.size = CGSizeMake(width, height - width)
        titleLabel?.frame.origin = CGPointMake(0 , width)
    }
}
